#This is a script showing a number of examples of making # histograms in R # we want to generate the data in the given table source("../gnrnd4.R") gnrnd4(1497539102, 78301453) # as usual, verify that we have thee right values head( L1 ) # by default this shows us the first 6 values tail( L1 ) # by default this shows us the last 6 values # then to make a histogram we just use the hist() function hist( L1 ) # That is enough for the requirements of this course # but as we have seen before, it might be nice to # fix this up a bit hist( L1, xlim=c(140,240), ylim=c(0,30), main="Data from the first table on the background sheet.", xlab = "data values given in table 1", col=rainbow(11)) # 11 is more than I need abline(h=seq(0,30,5), lty="dotted", col="darkgray") # # Now look at table 2 # gnrnd4(723859503, 7800145) L1 hist(L1) # or, again, we can fix this up hist( L1, xlim=c(140,240), ylim=c(0,30), main="Data from the second table on the background sheet.", xlab = "data values given in table 2", col=rainbow(11)) # 11 is more than I need abline(h=seq(0,30,5), lty="dotted", col="darkgray") # do this again, but have the intervals closed on # on the left hist( L1, xlim=c(140,240), ylim=c(0,30), main="Data from the second table on the background sheet.", xlab = "data values given in table 2", col=rainbow(11), right=FALSE) # look at the sorted data to see why this has # changed the histogram sort( L1 ) # # Now look at table 3 # gnrnd4(1849829701, 79001403) L1 hist( L1 ) # # Now look at table 4 # gnrnd4(1849829704, 18001800) L1 hist( L1 ) # and then let us make the histogram look a # bit better hist( L1, main="Data from Table 4: a Normal distribution", ylim=c(0,25), col=rainbow(8), xlab="Values from Table 4", las=1) abline(h=seq(0,25,5), lty="dashed", col="darkgrey") # # Now look at table 5 # # this time we are using gnrnd5 so load that # function into our environment source("../gnrnd5.R") gnrnd5(143879025405, 124001500, 134002100) head(L1) tail(L1) hist(L1) # again, we will pretty up the graph hist( L1, breaks=16, xlim=c(100,250), ylim=c(0,60), main="Data from Table 5: a Bimodal Distribution", las=2, xaxp=c(100, 250, 15), xlab="Data from Table 5", col=rainbow(16)) abline( h=seq(10,60,10), lty="dashed", col="grey")